---恐惧
---@class BuffEffect60 : BaseBuffEffect
BuffEffect60 = ClientFight.CreateClass("BuffEffect60", ClientFight.BaseBuffEffect)
local t = BuffEffect60
---@param fight Fight
---@param buff FighterBuff
local BUFF_EFFECT_60_LAST_RANDOM = "BUFF_EFFECT_60_LAST_RANDOM";
function t:action(fight, buff, ...)
    local parameters = {...};
    self:randomPoint(fight, buff, buff.target);
    return ClientFight.BaseBuffEffect.action(self,fight, buff, parameters);
end
function t:add(fight, buff)
    self:randomPoint(fight, buff, buff.target);
    return ClientFight.BaseBuffEffect.add(self, fight, buff);
end

function t:randomPoint(fight, buff, fighter)
    local list = { 1, 2, 3, 4 };
    local lastRandom = buff.effectParams[BUFF_EFFECT_60_LAST_RANDOM] or 0;
    list[table.containsIndex(list, lastRandom)] = nil;

    local random = list[fight:random(table.getn(list))];
    local pos = createPos(random);
    fighter.movePosition = pos;

    ReportManager.setMoveEndToJsonString(fight, fighter, fighter.moveAction);
    fighter.moveAction = ReportManager.moveToJsonString(fight, fighter);
    table.insert(fight.actions, fighter.moveAction);
    FightManager.playActions(fighter.moveAction)

    buff.effectParams[BUFF_EFFECT_60_LAST_RANDOM] = random;
    SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s恐惧buff %s 变更目的地为%s", fight.frame, fighter.fighterId, buff.modelId, pos));
end

function t:createPos(type)
    local centerX = (Global.FIGHT_INNER_ROUND[1][1] + Global.FIGHT_INNER_ROUND[2][1]) / 2;
    local centerY = (Global.FIGHT_INNER_ROUND[1][3] + Global.FIGHT_INNER_ROUND[2][3]) / 2;
    if type == 1 then
        return Vector2.New(Global.FIGHT_INNER_ROUND[1][1], centerY);
    elseif type == 2 then
        return Vector2.New(Global.FIGHT_INNER_ROUND[2][1], centerY);
    elseif type == 3 then
        return Vector2.New(centerX, Global.FIGHT_INNER_ROUND[1][3]);
    else
        return Vector2.New(centerX, Global.FIGHT_INNER_ROUND[2][3]);
    end
end
t.New()